import "../../../scss/activity/user_list.scss"
import $ from "jquery"
import Vue from "vue"
import moment from "moment"
import com from "../../utils/common"
import Scroll from "../../utils/rankSrcoll"
let page = {
  _actid:com.getUrlParam("actid") ? com.getUrlParam("actid") :0,
  _app: {},

  _appData: {
    JoinerRank: [
    ],
  },
  _init: function () {
    let self = this;

    com.ajax({
      url: "/act/getActAllJoinRank",
      data: {
        PageNum: 20,
        Actid: page._actid,
        PageSize:1,
      },
      ok:function (data) {
        self._appData.Catgory = data["Catgory"];
        console.log(self._appData)
        console.log( data["Catgory"])
        if(data["Catgory"] == "group_buy/group_buy"){
          window.location = "/dist/activity/group_buy/group_list.html"+window.location.search
        }
        if(data["Catgory"] == "group_buy/million_buy"){
          $("ul >li:last-child").css("width","40%")
        }
        self._analysisData(data["res"]);
        let obj = {
          url: "/act/getActAllJoinRank",
          data: {
            PageNum: 20,
            Actid: page._actid,
          },
          callback: self._analysisData
        }
        Scroll.PageSize ++;
        Scroll.StartScroll(obj)
        self._loadData();
      },
    })


  },
  // 解析排行榜
  _analysisData: function (data) {
    console.log(data)
    for (let i = 0; i < data.length; i++) {

      page._appData.JoinerRank.push({
        Name: data[i].Name,
        Mobile: data[i].Mobile,
        Current: data[i].Current,
        Time:data[i].Time ? moment(data[i].Time).format("YYYY-MM-DD HH:mm") : 0,
      })
    }
  },
  _loadData: function () {
    let self = this;
    self._app = new Vue({
      el: "#app",
      data: self._appData,
      methods: {},
    })
    self._afterLoad()
  },
  _afterLoad: function () {
    let self = this;
    self._setListener($(".header_nav ul li"), "select");
  },

  _setListener: function (btn, className) { // 点击切换导航栏
    let btnClick = btn;
    btn.click(function () {
        let $index = $(this).index();
        $(this).addClass(className).siblings().removeClass(className);
      }
    )
  }
};
page._init()